home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13879 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  43 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.inap.net!news1!ind-001-236-76
  3. From: dlmiller@iquest.net (Doug Miller)
  4. Subject: Re: reversing a string
  5. X-Nntp-Posting-Host: ind-001-236-76.iquest.net
  6. Message-ID: <DpnFtK.C1w@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Network Services
  9. X-Newsreader: News Xpress Version 1.0 Beta #2.1
  10. References: <4k6cjl$j8f@central.server.swt.edu> <4k6jks$fh9@solutions.solon.com> <DpLtt5.Lqu@iquest.net> <829135845snz@genesis.demon.co.uk>
  11. Date: Wed, 10 Apr 1996 13:53:45 GMT
  12.  
  13. Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
  14. >In article <DpLtt5.Lqu@iquest.net> dlmiller@iquest.net "Doug Miller" writes:
  15. >
  16. >>seebs@solutions.solon.com (Peter Seebach) wrote:
  17. >>>I can't see a way to reverse in place without a temporary of some sort,
  18. >>>or a loop of some sort, or something which is fundementally equivalent
  19. >>>to one of those.  There may be one, but I don't know it.
  20. >>>
  21. >>>-s
  22. >>
  23. >>How about this:
  24. >>
  25. >>void swap (char *s) {
  26. >>    if (strlen(s) > 1) {
  27. >
  28. >strlen() is fundamentally based on a loop.
  29. >
  30. >--
  31. >-----------------------------------------
  32. >Lawrence Kirby | fred@genesis.demon.co.uk
  33. >Wilts, England | 70734.126@compuserve.com
  34. >-----------------------------------------
  35.  
  36. OK, since the objective is to determine if the string is more than 1 character long, we can do
  37. the same by testing the next character.
  38. Replace
  39.     if (strlen(s) > 1)
  40. with
  41.     if (*(s + 1))
  42. and the rest of the algorithm is still valid.
  43.